package com.student.education.controller;

import com.student.education.common.CommonPage;
import com.student.education.common.CommonResult;
import com.student.education.service.CheckWorkService;
import com.student.education.to.CheckWorkQueryTo;
import com.student.education.to.CheckWorkTo;
import com.student.education.util.ExcelUtils;
import com.student.education.vo.CheckWorkVo;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 考勤表(CheckWork)表控制层
 *
 * @author makejava
 * @since 2021-09-25 16:18:36
 */
@RestController
@RequestMapping("/checkWork")
public class CheckWorkController {
    /**
     * 服务对象
     */
    @Resource
    private CheckWorkService checkWorkService;

    /**
     * 考勤表(CheckWork)表 Excel导入
     * @param file
     */
    @PostMapping("/upload")
    public CommonResult<String> readExcel(@RequestBody MultipartFile file){
        System.out.println("上传的文件："+file.getOriginalFilename());
        List<CheckWorkTo> list = ExcelUtils.readExcel("", CheckWorkTo.class, file);
        int total = checkWorkService.insert(list);
        if (total>0){
            CommonResult.success("导入成功");
        }
        return CommonResult.error("导入失败");
    }
    /**
     * 考勤表(CheckWork)表 模板下载
     * @param response
     */
    @GetMapping("/downloadModel")
    public void downloadModel(HttpServletRequest request, HttpServletResponse response){
        List<CheckWorkTo> empList = new ArrayList<>();
        ExcelUtils.writeExcel(request,response, empList, CheckWorkTo.class);
        return;
    }

    /**
     * 考勤表(CheckWork)表 考勤查询
     * @param
     */
    @PostMapping("/queryAll")
    public CommonResult<CommonPage<CheckWorkQueryTo>> queryAll(@RequestBody CheckWorkVo vo){
        return CommonResult.success(checkWorkService.queryAll(vo));
    }


}

